package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.BdRepayAccLoanTempDao;
import com.fdb.efp.nls.service.domain.BdRepayAccLoanTemp;
import com.fdb.efp.nls.service.facade.BdRepayAccLoanTempService;
import com.fdb.efp.nls.service.vo.BdRepayAccLoanTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 还款信息还款计划借据临时表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-04
 */
@Service("bdRepayAccLoanTempService")
public class BdRepayAccLoanTempServiceImpl implements BdRepayAccLoanTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdRepayAccLoanTempServiceImpl.class);

	@Autowired
	private BdRepayAccLoanTempDao bdRepayAccLoanTempDao;

	/**
	 * 新增操作
	 */
	public int insertBdRepayAccLoanTemp(BdRepayAccLoanTempVO inBdRepayAccLoanTempVo) {
		logger.debug("当前新增数据为:" + inBdRepayAccLoanTempVo.toString());
		int num = 0;
		try {
			BdRepayAccLoanTemp bdRepayAccLoanTemp = new BdRepayAccLoanTemp();
			beanCopy(inBdRepayAccLoanTempVo, bdRepayAccLoanTemp);
			num = bdRepayAccLoanTempDao.insertBdRepayAccLoanTemp(bdRepayAccLoanTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdRepayAccLoanTempVO inBdRepayAccLoanTempVo) {
		logger.debug("当前删除数据条件为:" + inBdRepayAccLoanTempVo);
		int num = 0;
		try {
			BdRepayAccLoanTemp bdRepayAccLoanTemp = new BdRepayAccLoanTemp();
			beanCopy(inBdRepayAccLoanTempVo, bdRepayAccLoanTemp);
			num = bdRepayAccLoanTempDao.deleteByPk(bdRepayAccLoanTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdRepayAccLoanTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdRepayAccLoanTempVO inBdRepayAccLoanTempVo) {
		logger.debug("当前修改数据为:" + inBdRepayAccLoanTempVo.toString());
		int num = 0;
		try {
			BdRepayAccLoanTemp bdRepayAccLoanTemp = new BdRepayAccLoanTemp();
			beanCopy(inBdRepayAccLoanTempVo, bdRepayAccLoanTemp);
			num = bdRepayAccLoanTempDao.updateByPk(bdRepayAccLoanTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdRepayAccLoanTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdRepayAccLoanTempVO queryByPk(BdRepayAccLoanTempVO inBdRepayAccLoanTempVo) {

		logger.debug("当前查询参数信息为:" + inBdRepayAccLoanTempVo);
		try {
			BdRepayAccLoanTemp queryBdRepayAccLoanTemp = new BdRepayAccLoanTemp();
			beanCopy(inBdRepayAccLoanTempVo, queryBdRepayAccLoanTemp);
			BdRepayAccLoanTemp queryRslBdRepayAccLoanTemp = bdRepayAccLoanTempDao.queryByPk(queryBdRepayAccLoanTemp);
			if (Objects.nonNull(queryRslBdRepayAccLoanTemp)) {
				BdRepayAccLoanTempVO outBdRepayAccLoanTempVo = beanCopy(queryRslBdRepayAccLoanTemp, new BdRepayAccLoanTempVO());
				logger.debug("当前查询结果为:" + outBdRepayAccLoanTempVo.toString());
				return outBdRepayAccLoanTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayAccLoanTempVO> queryAll(BdRepayAccLoanTempVO bdRepayAccLoanTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdRepayAccLoanTempVO> list = null;
		try {
			List<BdRepayAccLoanTemp> bdRepayAccLoanTemps = bdRepayAccLoanTempDao.queryAllByPage(bdRepayAccLoanTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdRepayAccLoanTemps.size());
			pageSet(bdRepayAccLoanTemps, bdRepayAccLoanTempVo);
			list = (List<BdRepayAccLoanTempVO>) beansCopy(bdRepayAccLoanTemps, BdRepayAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayAccLoanTempVO> queryAllCurrOrg(BdRepayAccLoanTempVO bdRepayAccLoanTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdRepayAccLoanTemp> bdRepayAccLoanTemps = bdRepayAccLoanTempDao.queryAllCurrOrgByPage(bdRepayAccLoanTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdRepayAccLoanTemps.size());
		List<BdRepayAccLoanTempVO> list = null;
		try {
			pageSet(bdRepayAccLoanTemps, bdRepayAccLoanTempVo);
			list = (List<BdRepayAccLoanTempVO>) beansCopy(bdRepayAccLoanTemps, BdRepayAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdRepayAccLoanTempVO> queryAllCurrDownOrg(BdRepayAccLoanTempVO bdRepayAccLoanTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdRepayAccLoanTemp> bdRepayAccLoanTemps = bdRepayAccLoanTempDao.queryAllCurrDownOrgByPage(bdRepayAccLoanTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdRepayAccLoanTemps.size());
		List<BdRepayAccLoanTempVO> list = null;
		try {
			pageSet(bdRepayAccLoanTemps, bdRepayAccLoanTempVo);
			list = (List<BdRepayAccLoanTempVO>) beansCopy(bdRepayAccLoanTemps, BdRepayAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 
	 * 分页查询【还款计划借据临时表】 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:04:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:04
	 * @date 2019年3月23日 下午12:11:04
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BdRepayAccLoanTempVO> queryByPage(BdRepayAccLoanTempVO BdRepayAccLoanTempVO) {
		String msg1 = "分页查询还款计划借据临时表";
		logger.debug(msg1, "message {}");
		List<com.fdb.efp.nls.service.vo.BdRepayAccLoanTempVO> list = null;
		try {
			List<BdRepayAccLoanTemp> BdRepayAccLoanTemps = bdRepayAccLoanTempDao.queryByPage(BdRepayAccLoanTempVO);
			list = (List<com.fdb.efp.nls.service.vo.BdRepayAccLoanTempVO>) beansCopy(BdRepayAccLoanTemps, com.fdb.efp.nls.service.vo.BdRepayAccLoanTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【还款计划借据临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【还款计划借据临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = bdRepayAccLoanTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【还款计划借据临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
